
import { DialogModel } from '../model/question/DialogModel'


import  httpUtils  from '../utils/HttpUtils'
import promptAction from '@ohos.promptAction'
import { ShowMessageEnum } from '../utils/enmu/ShowMessageEnum'
/**
 * 获取新闻热搜数据
 */

class DialogAPI {
  // 分页查询 历史问答记录
  async getDialogHistory(userId: string,pageNum: number = 1, pageSize:number = 10): Promise<DialogModel[]> {
    let res = await httpUtils.get(`/dialoghistory/dialoghistory/list?pageNum=${pageNum}&pageSize=${pageSize}&userId=${userId}`)
    if (res.code !== 200) {
      promptAction.showToast({
        message: ShowMessageEnum.DIALOG_GET_HISTORY_DATA_ERROR,
        duration: 2000,
        bottom: 50
      });
      return
    }
    return res.rows
  }
  // 问答接口
  async getAnswer(userId: string, question: string, modelUsed: string): Promise<DialogModel>{
    let res = await httpUtils.post(`/dialoghistory/dialoghistory/glm`, {
      "userId": userId,
      "question": question,
      "modelUsed": modelUsed
    })
    if (res.code!==200) {
      promptAction.showToast({
        message: ShowMessageEnum.NETWORK_ERROR,
        duration: 2000,
        bottom: 50
      });
      return
    }
    return res.data
  }

}

let dialogAPI = new DialogAPI()

export default dialogAPI
